<?php

class FlashACtion extends IntesysAction
{


    public function ftest(){
		    import("@.ORG.Affiliate.GloballwnCashbacklevel");
            $class = 'GloballwnCashbacklevel';
                                                            
          
		
		
	    	$a = new $class(0,$this->siteid);
			
			//$html = $Threelevel->createform();
		    //$this->formhtml = $html;
		    //$this->display();
		
	    
		
		
		
		}
		
	public function savetest(){
		
		
		import("@.ORG.Affiliate.GlobalCashbacklevel");
             $class = 'GlobalCashbacklevel';
		$a = new $class(0,$this->siteid);
        dump($a->saveform());
		
		}	
		
	public function gets(){
		import("@.ORG.Affiliate.GlobalCashbacklevel");
        $class = 'GlobalCashbacklevel';
		$a = new $class(0,$this->siteid);
		$id=219591;
        dump($a->getPid($id));
		
	
		}	
		
		


    public function remove(){
	  if($this->_post('id')!=null){
		 $taskDB=M('task');
		 $task_info=$taskDB->where('site_id = '.__SITEID__.' and swf_path  like  "%'.$this->_post('id').'%" ')->find();
		 $i=0;
		 $swf=array_filter(explode('.*.',$task_info['swf_path']));
		 foreach($swf as $key => $val){
		 $tmp=null;
		 $tmp=json_decode($val);
		 foreach($tmp as $tkey => $tval){
		 if($tkey=='swf'){
		 if($tval==$this->_post('id')){

		 $swf_name=json_decode($tval);	 
		 continue;
       	 }else{
		 $new_data[]=$tmp;	 
			 }
				 }
			 }
		 $i++;	 
		 }
	
     	
		foreach($new_data as $nkey => $nval){
			if($nval!=null){
			$str.=json_encode($nval).".*.";
			}
		}	
		$data['swf_path']=$str;
		$res=$taskDB->where('site_id = '.__SITEID__.' and id = '.$task_info['id'])->save($data);
     	
		if($res){
		$info['error']='删除成功';
		$info['status']='0';	
		$info['url']='';
		}
		
	
		$swf_path="Public/Uploads/".__SITEID__."/swf/".$this->_post('id').".swf";
		unlink($swf_path);
		}
	    echo json_encode($info);
		}

   //展示swf用
    public function index()
    {
        if ($_GET['id'] != null) {
            $swf = __SITEID__.'/swf/'.$_GET['id'];
        } else {
            $swf = '1486433603';
        }
        
		
        $this->assign('swf', $swf);
        $this->display();
	}


    //直接调用start方法就好，传文件的路径然后就会自动保存和转换文件，会保存源文件和swf文件
    public function start($filePath)
    {
        Vendor("PHPExcel.word2pdf");
        $name = time();
        $word2pdf = new word2pdf();
		//$savePath=$this->fileCreat('./Public/Uploads/'.__SITEID__.'/tmp/');
        $pdfPath=$this->fileCreat('./Public/Uploads/'.__SITEID__.'/pdf/');
		$swfPath=$this->fileCreat('./Public/Uploads/'.__SITEID__.'/swf/');
       // $info = $this->upload($savePath);
        if ($filePath!=null) {
       
            $name = time();
            $word2pdf->fileName = './Public/'.$filePath;
         //   $word2pdf->filePath = $info[0]['savepath'];
			
            $word2pdf->pdfName = $pdfPath.$name . '.pdf';
            $word2pdf->swfName = $swfPath.$name . '.swf';
            if ($info[0]['extension'] != 'pdf') {
                $pdfPath = $word2pdf->topdf();
            }
            $swfPath = $word2pdf->toswf();
          
        }
        if (! file_exists($info[0]['savepath'] . $name . '.pdf')) {
            $info['pdf'] = 'pdf转换失败';
        }
        if (! file_exists($info[0]['savepath'] . $name . '.pdf')) {
            $info['swf'] = 'swf转换失败';
        }
       // dump($pdfPath);
       // dump($swfPath);

	  
        $info['swf'] =$name;
		
		unlink('./Public/Uploads/'.__SITEID__.'/pdf/'.$name.'.pdf');
        return $info;
    }

    public function upload($savePath)
    {
        import('ORG.Net.UploadFile');
        $upload = new UploadFile(); // 实例化上传类
        $upload->maxSize = 3145728; // 设置附件上传大小
        $upload->allowExts = array(
            'xlsx',
            'xls',
            'doc',
            'opt',
            'odp',
            'odt',
            'ods',
            'docx',
            'ppt',
            'pptx',
            'pdf'
        ); // 设置附件上传类型
        $upload->savePath = $savePath; // 设置附件上传目录
        if (! $upload->upload()) { // 上传错误提示错误信息
            $this->error($upload->getErrorMsg());
        } else { // 上传成功 获取上传文件信息
            $info = $upload->getUploadFileInfo();
        }
        return $info;
    }

    public function fileCreat($path)
    {
        if (! file_exists($path)) {
            mkdir($path, 0755);
        }else{
			$path=$path;
			}
		return $path;
    }
	
}


